package cn.itsource.login.service.impl;

import cn.itsource.login.service.IEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
@Service
public class EmailServiceImpl implements IEmailService {
    @Autowired
    private JavaMailSender javaMailSender;
    @Value("${spring.mail.username}")
    private String from;
    @Override
    public void sendActMail(String email, Long id) {
        //创建SimpleMailMessage对象
        MimeMessage message = javaMailSender.createMimeMessage();
        try {
            MimeMessageHelper helper = new MimeMessageHelper(message,true,"utf-8");
            //邮件发送人
            helper.setFrom(from);
            //邮件接收人
            helper.setTo(email);
            //邮件主题
            helper.setSubject("宠物之家店铺激活");
            //邮件内容，html格式
            helper.setText("<h2>请前去激活</h2>"+"欢迎使用宠物之家店铺，请"+
                    "<a href='http://127.0.0.1:8080//act/email/"+id+"'>点击激活</a>",true);
            //发送
            javaMailSender.send(message);
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }
}